package com.bluerose.www;

/**
 * @PROJECT_NAME: java_2022_11_26
 * @DESCRIPTION:
 * @USER: Administrator
 * @DATE: 2022/11/26 20:14
 */


import java.util.*;
import java.io.FileNotFoundException;
import java.io.PrintWriter;

public class test
{
    public static void testTreeMap() throws FileNotFoundException
    {
        TreeMap<String, Double> staff = new TreeMap<>();
        staff.put("1001", 4231.4);
        staff.put("1004", 4132.5);
        staff.put("1002", 3689.6);
        staff.put("1003", 3103.3);
        staff.put("1008", 3846.3);
        staff.put("1010", 3756.1);
        staff.put("1005", 4156.7);
        staff.put("1009", 3956.8);
        staff.put("1006", 2989.6);
        staff.put("1007", 4356.9);
        TreeSet<String> resultSortedById = new TreeSet<>((String::compareTo));
        resultSortedById.addAll(staff.keySet());
        System.out.println("按工号排序");
        for (String key: resultSortedById)
        {
            System.out.println("工号: " + key + "; 工资: " + staff.get(key));
        }

        List<Map.Entry<String, Double>> resultSortedBySalary = new ArrayList<Map.Entry<String, Double>>(staff.entrySet());
        resultSortedBySalary.sort((o1, o2) -> o1.getValue().compareTo(o2.getValue()));
        System.out.println("按工资排序");
        for (Map.Entry<String, Double> e: resultSortedBySalary)
        {
            System.out.println("工号: " + e.getKey()+"; 工资: "+e.getValue());
        }

        PrintWriter fileOut = new PrintWriter("staff.txt");
        fileOut.println("按工号排序");
        for (String key: resultSortedById)
        {
            fileOut.println("工号: " + key + "; 工资: " + staff.get(key));
        }
        fileOut.println("按工资排序");
        for (Map.Entry<String, Double> e: resultSortedBySalary)
        {
            fileOut.println("工号: " + e.getKey()+"; 工资: "+e.getValue());
        }
        fileOut.close();
    }

    public static void main(String[] args) throws FileNotFoundException {
        try
        {
            testTreeMap();
        }
        catch(FileNotFoundException e)
        {
            System.out.println(e.fillInStackTrace().toString());
        }
    }
}

//public class test
//{
//    public static void testArrayList()
//    {
//        ArrayList<Integer> arr = new ArrayList<>();
//        for (int i = 1; i < 51; ++i)
//        {
//            arr.add(i);
//        }
//        for (int i = 49; i > 0; i -= 2)
//        {
//            System.out.print(arr.get(i) + " ");
//        }
//    }
//    public static void main(String[] args)
//    {
//        testArrayList();
//    }
//}
